from libs.pyqt5braisedpork.window.generic import BaseWindow
from libs.portScanner import PortScannerThread
from .controller import YeChatController

from ui.client.yeChat import Ui_ye_chat_client


class YeChatWindow(BaseWindow, Ui_ye_chat_client, YeChatController):
    """yeChat 主功能窗口"""

    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.qss = "static/qss/client.qss"
        self.qss_render()

        self.addition_ui()

        self.port_scanner_thread = PortScannerThread(self)  # 端口扫描线程类
        self.signal_binder()

    def addition_ui(self):
        """附加的 UI 变更"""
        effect_shadow = self.get_shadow((198, 201, 255), 3, offset=(2, 3))
        self.label_status.setGraphicsEffect(effect_shadow)
        self.set_max_thread()  # 变更最大可操作线程数

    def signal_binder(self):
        """信号绑定"""
        self.horizontalSlider_threadNum.valueChanged.connect(self.lcdNumber_threadNum.display)  # 最大线程数显示

        self.pushButton_scanStart.clicked.connect(lambda: self.port_scanner_thread.start())  # 端口扫描开始
        self.port_scanner_thread.set_port_status.connect(self.add_browser_text)    # 填充端口扫描信息到信息栏
        self.pushButton_clearScanMsg.clicked.connect(self.textBrowser_scanMsg.clear)  # 清空端口扫描信息框
